package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.*;
import com.sky.entity.Orders;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.validation.constraints.AssertTrue;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);
    @Update("update orders set status = #{orderStatus}, pay_status = #{orderPaidStatus}, checkout_time = #{checkOutTime} where number = #{orderNumber}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime checkOutTime, String orderNumber);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    void update(Orders orders);
    @Select("select * from orders where id = #{id}")
    Orders getOrderById(Long id);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
    @Update("update orders set status = #{cancelled},cancel_time=#{cealTime} where id = #{id}")
    void updateStatus2(Long id, Integer cancelled,LocalDateTime cealTime);
    @Select("select * from orders where number = #{orderNumber}")
    Orders SelectOrder(String orderNumber);

    Page<Orders> page2Query(String number, String beginTime, String endTime, Integer status,String phone);
    @Select("select name from order_detail where order_id = #{orderId}")
    List<String> getOrderDishes(Long orderId);
    @Update("update orders set status = #{confirmed} where id = #{id}")
    void updateStatus3(Long id, Integer confirmed);
    //获取全部订单信息
    @Select("select * from orders")
    List<Orders> getOedersAll();
    @Update("update orders set status = #{cancelled},cancel_time= #{now},cancel_reason = #{cancelReason} where id = #{id}")
    void updateStatus4(Long id, Integer cancelled, String cancelReason, LocalDateTime now);

    Double sumByMap(Map map);
    Integer countByMap(Map map);
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
    @Select("SELECT status as status,count(status) as number from orders where status in (4,3,2) group by status")
    List<OrderStatisticsDTO> statisticscs();
    @Update("update orders set status = #{deliveryInProgress} where id = #{id}")
    void updateStatus5(Long id, Integer deliveryInProgress);
    @Update("update orders set status = 6, rejection_reason=#{rejectionReason}where id = #{id}")
    void reject(OrdersRejectionDTO ordersRejectionDTO);
}
